package com.zf.museum.controller;


import com.zf.museum.bean.Question;
import com.zf.museum.bean.Result;
import com.zf.museum.model.SingleChoice;
import com.zf.museum.service.SingleChoiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(description = "单选题")
@RestController
@RequestMapping("/single")
public class SingleChoiceController {

    @Autowired
    private SingleChoiceService singleChoiceService;

    @ApiOperation(value = "上传题目", notes = "上传含有Excel表格的题目")
    @PostMapping("/upload")
    @RequiresRoles("admin")
    public Result upload(MultipartFile file) {

        return singleChoiceService.upload(file);
    }

    @ApiOperation(value = "查看所有题目")
    @GetMapping("/findAll")
    @RequiresRoles("admin")
    public List<SingleChoice> findAll() {

        return singleChoiceService.findAll();
    }

    @ApiOperation(value = "修改题目内容", notes = "返回修改后的所有题目")
    @ApiImplicitParam(name = "singleChoices", value = "题目的集合", dataType = "SingleChoice")
    @PostMapping("/update")
    @RequiresRoles("admin")
    public Result update(@RequestBody List<SingleChoice> singleChoices) {
        return singleChoiceService.update(singleChoices);
    }

    @ApiOperation(value = "删除题目", notes = "返回删除的题数")
    @ApiImplicitParam(name = "ids", value = "题目id的集合", dataType = "Array[long]")
    @PostMapping("/delete")
    @RequiresRoles("admin")
    public Result delete(@RequestBody List<Long> ids) {

        return singleChoiceService.delete(ids);
    }

    @ApiOperation(value = "获取6道题目")
    @GetMapping("/getSingleChoice")
    public List<SingleChoice> getSingleChoice(@RequestParam("openId") String openId) {

        return singleChoiceService.getSingleChoice(openId);
    }

}
